import {apiClient, publicClient} from './api/client'
import {setupInterceptors} from './api/interceptors'
import {BaseApiClient} from './api/requests'
import type {RequestConfig} from '@/types/api'

// 设置需要认证的API客户端拦截器
setupInterceptors(apiClient)

// 创建需要认证的API客户端
const authenticatedClient = new BaseApiClient(apiClient)

// 创建公共API客户端（不需要拦截器）
const publicApiClientInstance = new BaseApiClient(publicClient)

// 导出便捷的请求方法
export const ApiClient = {
    get: <T = any>(url: string, config?: RequestConfig) => authenticatedClient.get<T>(url, config),
    post: <T = any>(url: string, data?: any, config?: RequestConfig) => authenticatedClient.post<T>(url, data, config),
    put: <T = any>(url: string, data?: any, config?: RequestConfig) => authenticatedClient.put<T>(url, data, config),
    patch: <T = any>(url: string, data?: any, config?: RequestConfig) => authenticatedClient.patch<T>(url, data, config),
    delete: <T = any>(url: string, config?: RequestConfig) => authenticatedClient.delete<T>(url, config),
    upload: <T = any>(url: string, formData: FormData, config?: RequestConfig) => authenticatedClient.upload<T>(url, formData, config),
    download: (url: string, filename?: string, config?: RequestConfig) => authenticatedClient.download(url, filename, config)
}

// 导出公共API客户端实例
export const publicApiClient = publicApiClientInstance

// 导出类型定义
export type {ApiResult, RequestConfig} from '@/types/api'